// components/tabs/index.js
Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		tabs: {
			type: Array,
			value: []
		}
	},

	/**
	 * 组件的初始数据
	 */
	data: {
		current: 0,
		linePostionX: 0,
		linePositionWidth: 0
	},

	lifetimes: {
		attached() {
			this.calculateLinePositionX()
		}
	},
	/**
	 * 组件的方法列表
	 */
	methods: {
		onTab(e) {
			const {
				index
			} = e.currentTarget.dataset
			this.setData({
				current: index
			})

			this.calculateLinePositionX(index)
		},
		calculateLinePositionX(index = 0) {
			let linePostionX = 0

			this.createSelectorQuery().select(".active").boundingClientRect(rect => {
				let currentCenterX = rect.left + rect.width / 2
				let linePositionWidth = rect.width*0.8
				linePostionX = currentCenterX - linePositionWidth/2 -10
				this.setData({
					linePostionX,
					linePositionWidth
				})
				// console.log(linePostionX);
			}).exec()

		}
	}
})